# !/usr/bin/env python3
# @author : walker
# @data : 2019/9/11

from config import *

class Get_company_urls:
    def __init__(self):
        pass

    '''
        请求并返回页面
    '''
    @staticmethod
    def company_url_search(add_url):
        try:
            # '/hotList/hot/type/factory.html'
            res = requests.get(URL + add_url)
            if res.status_code == 200:
                return res.text
            return company_url_search()
        except Exception as e:
            return company_url_search()

    '''
        解析页面信息，保存厂商url及产品数量信息
    '''
    def parse_company_page(self,add_url):
        #获取到该url页面中的详细信息
        company_page_content = self.company_url_search(add_url)
        soup = BeautifulSoup(company_page_content,'lxml')
        company_data = soup.findAll(name="div",attrs={"class" : "thumbnail"})
        i = 0
        for company_item in company_data:
            # i += 1
            company_info = company_item.findAll(name = "p",attrs={"class":"item_p"})
            # db_prototype_dataset_info['prototype_company_data_info'].save({"company_name":company_info[0].string,"company_prototype_numbers":company_info[1].string,"company_goods_url":company_item.a.get('href')})
        # print(i)
